% SalColorMap - Saliency Color Mapping
% Map conventional RGB image to special color space used for saliency.
%
% USAGE:
% [I R G B Y] = SalColorMap(img)
%
% INPUT:
% img - m by n by 3 array containing RGB image 
%
% OUTPUTS:
% I - m by n array containing intensity component
% R - m by n array containing red component
% G - m by n array containing green component
% B - m by n array containing blue component
% Y - m by n array containing yellow component
%
% These mappings are based on the description in the paper "Realistic
% Avater Eye and Head Animation Using a Neurobiological Model of Visual
% Attention" by Itti, Dhavale, and Pighin
%
function [I R G B Y] = SalColorMap(img)
    rc = 1; gc = 2; bc = 3;
    I = mean(img, 3);
    scale = IScale(I); % Pointwise scaling matrix - reciprocals except for
                       % small values, which are set to zero
    % Extract normalized r, g, b components
    r = squeeze(img(:,:,rc)).*scale;
    g = squeeze(img(:,:,gc)).*scale;
    b = squeeze(img(:,:,bc)).*scale;
    % Map to RGBY space.
    R = max(0, r - (g + b)./2);
    G = max(0, g - (r + b)./2);
    B = max(0, b - (g + r)./2);   
    Y = max(0, (r + g)./2 - abs(r - g)./2 - b);
